#include "BlockQueue.hpp"
#include "Task.hpp"
#include <unistd.h>

void* productor(void* args)
{
    BlockQueue<task_t>* bq = static_cast<BlockQueue<task_t>*>(args);
    task_t t = Download;
    while(true)
    {
        bq->push(t);
        std::cout << "生产者生产了一个任务" << std::endl;
    }

    return nullptr;
}

void* consumer(void* args)
{
    BlockQueue<task_t>* bq = static_cast<BlockQueue<task_t>*>(args);
    while(true)
    {
        task_t t = bq->pop();
        t();
        std::cout << "消费者执行了一个任务" << std::endl;
        sleep(1);
    }

    return nullptr;
}

int main()
{
    pthread_t p,c;

    BlockQueue<task_t>* bq = new BlockQueue<task_t>;

    pthread_create(&p, nullptr, productor, bq);

    pthread_create(&c, nullptr, consumer, bq);

    pthread_join(p, nullptr);
    pthread_join(c, nullptr);

    return 0;
}